package com.example.wxy2.controller;

import com.example.wxy2.entity.data;
import com.example.wxy2.entity.rules;
import com.example.wxy2.entity.stateDto;
import com.example.wxy2.entity.state_entity;
import com.example.wxy2.service.TestService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import sun.util.resources.LocaleData;

import java.text.DateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@RestController
public class massageController {

    @Autowired
    private TestService testService;

//    @GetMapping("bbb")
//    private int aaa(){
//        return 111;
//    }


//    @PostMapping("updateState")
//    private void updateState(@RequestBody stateDto stateDto){
//        testService.updatestate(stateDto);
//    }

    @PostMapping("updateState")
    @CrossOrigin
    private void updateState( @RequestBody stateDto stateDto){

        List<Integer> list2 = stateDto.getId();
        LinkedList<state_entity> list = new LinkedList<>();
        for (int id : list2) {
            state_entity entity = new state_entity();
            entity.setId(id);
            list.add(entity);
        }
        testService.updatestate(list);
//        testService.updatestate(stateDto);
    }


    @GetMapping("findPage")
    @CrossOrigin
    public PageInfo<data> findPage(@RequestParam(name = "pageNum", defaultValue = "1")Integer pageNum,
                             @RequestParam(name = "pageSize", defaultValue = "10")Integer pageSize,
                             @RequestParam(name = "username", defaultValue = "")String username,
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate time1 ,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate time2 ,
                                   @RequestParam(name = "state", defaultValue = "0")String state) {


        System.out.println(pageNum+"---"+time1+"---"+time2+"---"+ username+"---"+state+"---"+pageSize);



        return testService.find(pageNum,pageSize,username,time1,time2,state);

    }



    @PostMapping("updateRules")
    @CrossOrigin
    private void updateRules(@RequestBody  rules rules){
        System.out.println(rules);
        testService.updateRules(rules);
    }


    @PostMapping("getRules")
    @CrossOrigin
    public  List<rules> getRules(){

        return testService.getRules();
    }


}
